﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework.Db;
using System.Data;
using Framework.Kit;

namespace DAL.Service
{
    /// <summary>
    /// 拍卖会服务
    /// </summary>
    public class auctionService : DbBase
    {
        Model.auctionModel auction = new Model.auctionModel();
        List<Model.auctionModel> l=new List<Model.auctionModel>();

        /// <summary>
        /// 析构
        /// </summary>
        public auctionService()
        {
            this.tb = auction.tb;
        }

        /// <summary>
        /// 根据拍卖会ID获取拍卖会下信息
        /// </summary>
        /// <param name="auction_no"></param>
        /// <returns></returns>
        public Model.auctionModel getAuction(string auction_no)
        {
            try
            {
                string sql = string.Format("SELECT * FROM {0} WHERE  AUCTION_NO = '{1}'", this.tb, auction_no);
                DataTable dt = this.queryDtSQL(sql);
                if (dt.Rows.Count == 1)
                {
                    auction.Auction_ADD = dt.Rows[0]["AUCTION_ADD"].ToString();
                    auction.Auction_DATE = Convert.ToDateTime(dt.Rows[0]["AUCTION_DATE"]);
                    auction.Auction_NAME = dt.Rows[0]["AUCTION_NAME"].ToString();
                    auction.Auction_NO=dt.Rows[0]["AUCTION_NO"].ToString();
                    return auction;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                other.WriteErrLog("获取当前需要拍卖会信息", ex);
                return null;
            }
        }

        /// <summary>
        /// 获取当前日期的拍卖会
        /// </summary>
        /// <returns></returns>
        public List<Model.auctionModel> getAuctionLst()
        {
            try
            {
                string sql = string.Format("SELECT * FROM {0} WHERE  AUCTION_DATE = TO_DATE('{1}', 'YYYY-MM-DD') AND DEL_FLG='0' AND AUCTION_STATUS='AUCTION_STATUS01'", this.tb, DateTime.Now.ToShortDateString());
                DataTable dt = this.queryDtSQL(sql);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    l.Add(new Model.auctionModel {
                        Auction_ADD = dt.Rows[i]["AUCTION_ADD"].ToString(),
                        Auction_NAME = dt.Rows[i]["AUCTION_NAME"].ToString(),
                        Auction_DATE=Convert.ToDateTime(dt.Rows[i]["AUCTION_DATE"]),
                        Auction_NO = dt.Rows[i]["AUCTION_NO"].ToString()
                    });
                }
                return l;
            }
            catch (Exception ex)
            {
                other.WriteErrLog("获取当前日期的拍卖会列表", ex);
                return null;
            }
        }
    }
}
